import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/register.dart';
import 'package:ichinesereader/utils/helper.dart';
import 'package:reactive_forms/reactive_forms.dart';
import '../common/noticeText.dart';
import '../common/termText.dart';

// ignore: must_be_immutable
class TermForIndividal extends StatelessWidget {
  TermForIndividal({
    Key? key,
  }) : super(key: key);
  RegisterController _registerController = Get.put(RegisterController());
  Widget build(BuildContext context) {
    // String? product = Get.arguments;
    // String defaultType = '';
    // if (product == 'icr') {
    //   defaultType = 'icr-yearly';
    // } else if (product == 'ica') {
    //   defaultType = 'ap-mockexam';
    // }

    final form = FormGroup({
      // 'subscription': FormControl<String>(
      //     validators: [Validators.required], value: defaultType),
      'notice':
          FormControl<bool>(validators: [Validators.required], value: false),
      'terms':
          FormControl<bool>(validators: [Validators.required], value: false),
    });
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text("Payment".tr),
          leading: BackButton(onPressed: () {
            Get.toNamed('/account/create/individual/language');
          }),
        ),
        body: SafeArea(
            child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: MediaQuery.of(context).size.width > 1000
                  ? 1000
                  : MediaQuery.of(context).size.width * 0.95,
              child: Column(
                //crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: 16,
                  ),
                  // Text('Choose Subscription Type:'.tr,
                  //     style:
                  //         TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
                  // SizedBox(
                  //   height: 16,
                  // ),
                  ReactiveForm(
                    formGroup: form,
                    child: Column(children: <Widget>[
                      //     if (product == 'icr')
                      //       ReactiveSegmentedControl<String, String>(
                      //         formControlName: 'subscription',
                      //         unselectedColor: Get.theme.primaryColorLight,
                      //         padding: const EdgeInsets.all(0.0),
                      //         children: {
                      //           'icr-monthly':
                      //               Text('${Constants.icrTypes[0].title}'.tr,
                      //                   style: TextStyle(
                      //                     color: Color(0xff00599b),
                      //                     fontSize: 16.0,
                      //                     letterSpacing: 1.0,
                      //                   )),
                      //           'icr-yearly':
                      //               Text('${Constants.icrTypes[1].title}'.tr,
                      //                   style: TextStyle(
                      //                     color: Color(0xff00599b),
                      //                     fontSize: 16.0,
                      //                     letterSpacing: 1.0,
                      //                   ))
                      //         },
                      //       ),
                      //     if (product == 'ica')
                      //       ReactiveSegmentedControl<String, String>(
                      //         formControlName: 'subscription',
                      //         unselectedColor: Get.theme.primaryColorLight,
                      //         padding: const EdgeInsets.all(0.0),
                      //         children: {
                      //           'ap-testbank':
                      //               Text('${Constants.icaTypes[0].title}'.tr,
                      //                   style: TextStyle(
                      //                     color: Color(0xff00599b),
                      //                     fontSize: 16.0,
                      //                     letterSpacing: 1.0,
                      //                   )),
                      //           'ap-mockexam':
                      //               Text('${Constants.icaTypes[1].title}'.tr,
                      //                   style: TextStyle(
                      //                     color: Color(0xff00599b),
                      //                     fontSize: 16.0,
                      //                     letterSpacing: 1.0,
                      //                   )),
                      //           'ap-bundling':
                      //               Text('${Constants.icaTypes[2].title}'.tr,
                      //                   style: TextStyle(
                      //                     color: Color(0xff00599b),
                      //                     fontSize: 16.0,
                      //                     letterSpacing: 1.0,
                      //                   ))
                      //         },
                      //       ),
                      //     SizedBox(
                      //       height: 26,
                      //     ),
                      Text('Notice:'.tr,
                          style: TextStyle(
                              fontSize: 13, fontWeight: FontWeight.w600)),
                      SizedBox(
                        height: 16,
                      ),
                      NoticeTextWidget(),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          ReactiveCheckbox(
                            formControlName: 'notice',
                          ),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Text(
                              'read information'.tr,
                            ),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 26,
                      ),
                      Text('Terms & Conditions:'.tr,
                          style: TextStyle(
                              fontSize: 13, fontWeight: FontWeight.w600)),
                      SizedBox(
                        height: 16,
                      ),
                      TermTextWidget(),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          ReactiveCheckbox(formControlName: 'terms'),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Text(
                              'accept conditions'.tr,
                            ),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 16,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          OutlinedButton(
                            child: Text('Back'.tr,
                                style: TextStyle(
                                    fontSize: 16, fontWeight: FontWeight.w500)),
                            onPressed: () {
                              Get.toNamed('/account/create/individual/language',
                                  arguments: '${Get.arguments}');
                            },
                          ),
                          ReactiveFormConsumer(builder: (context, form, child) {
                            return OutlinedButton(
                              child: Text('Next'.tr,
                                  style: TextStyle(
                                      fontSize: 16,
                                      fontWeight: FontWeight.w500)),
                              onPressed: () {
                                if (form.control('notice').value == false ||
                                    form.control('terms').value == false) {
                                  // there is no validator meesage for checkox like form field, so use snackar
                                  showSnackMsg(
                                      'Please accept these conditions');
                                }
                                if (form.control('notice').value &&
                                    form.control('terms').value) {
                                  _registerController
                                      .getPaymentToken(
                                          _registerController.getUserInfo)
                                      .then((value) {
                                    Get.toNamed(
                                        '/account/create/individual/billing');
                                  });
                                }
                              },
                            );
                          }),
                          const SizedBox(width: 8),
                        ],
                      ),
                    ]),
                  ),
                ],
              ),
            ),
          ],
        )));
  }
}
